﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="conversationDetail.ascx.cs" Inherits="VISS.Web.Frontend.Modules.User.Profile.ConversationDetailControl" %>

<%@ Import Namespace="VISS.Web.Frontend" %>
<%@ Import Namespace="NCT.Framework" %>

<div id="conversation-page">
    <% if (ConversationMessages.Count > 0) { %>
    <div class="header">
        <div class="left">
            <a href="/profile?u=<%=OtherUserKey %>"><img src="<%=LoginFactory.RefeshAvatarThumbPath(OtherUserKey, OtherUserGender) %>" /></a>
            <div class="border"></div>
        </div>
        <div class="middle">
            <div class="title"><%=ConversationMessages[0].Title%></div>
            <div class="conversation-info">
                Tin nhắn giữa <span class="name"><a href="/profile?u=<%=OtherUserKey %>"><%=OtherUserName%></a></span> và <span class="name">bạn</span>
            </div>
        </div>
        <div class="right">
            <div class ="time">
                <span class="timeago" title="<%=ConversationMessages[LastIndex].DateCreated %>"></span>
            </div>
            <div class="report">
                <% if (CanDoAction) { %>
                        <span class="report-user" onclick="SendReportPopup('<%=OtherUserKey %>');">Báo vi phạm</span>
                <% } else { %>
                        <a href="javascript:void(0);" onclick="jAlert(VarifiedAccountRequired);"><span class="report-user" >Báo vi phạm</span></a>
                <% } %>
            </div>            
        </div>
    </div>
    <div id="messages">
<% for (int i = 0; i < ConversationMessages.Count - 1; i++) { %>
        <div class="message <% if (ConversationMessages[i].Status == VISS.API.Users.EUserMessageStatus.UnRead && ConversationMessages[i].ReceivedUserKey == CurrentUserKey) Response.Write("unread"); %>" id="Message-<%=ConversationMessages[i].ID %>" >
            <input type="hidden" id="MessageStatus-<%=ConversationMessages[i].ID %>" value="hide" />
            <div class="message-header" id="MessageHeader-<%=ConversationMessages[i].ID %>" onclick="ShowHideMessage('<%=ConversationMessages[i].ID %>')">
                <div class="name"><%=ConversationMessages[i].SenderName%></div>
                <div class="short-content">
                    <span id="ShortContent-<%=ConversationMessages[i].ID %>">
                        <% 
                            int index = ConversationMessages[i].Content.IndexOf("<br />", 0);
                            if (index < 0) {
                                Response.Write(StringUtils.CutStringChar(ConversationMessages[i].Content, 50));
                            }
                            else {
                                string shortContent = ConversationMessages[i].Content.Substring(0, index);
                                Response.Write(StringUtils.CutStringChar(shortContent, 50));
                            }
                        %>
                    </span>
                    &nbsp;
                </div>
                <div class="right">
                <% if (ConversationMessages[i].SentUserKey == CurrentUserKey) { %>
                    <input type="button" class="delete-message" onclick="DeleteMessage('<%=ConversationMessages[i].ID %>', 's')" title="Xóa tin nhắn này" />
                <% }
                   else { %>
                    <input type="button" class="delete-message" onclick="DeleteMessage('<%=ConversationMessages[i].ID %>', 'r')" title="Xóa tin nhắn này" />
                <% } %>
                </div>
            </div>
            <div class="content" id="MessageContent-<%=ConversationMessages[i].ID %>"><%=ConversationMessages[i].Content %></div>
        </div>
<% } %>
        <div class="message <% if (ConversationMessages[LastIndex].Status == VISS.API.Users.EUserMessageStatus.UnRead && ConversationMessages[LastIndex].ReceivedUserKey == CurrentUserKey) Response.Write("unread"); %>" id="Message-<%=ConversationMessages[LastIndex].ID %>" >
                <input type="hidden" id="MessageStatus-<%=ConversationMessages[LastIndex].ID %>" value="show" />
                <div class="message-header" id="MessageHeader-<%=ConversationMessages[LastIndex].ID %>" onclick="ShowHideMessage('<%=ConversationMessages[LastIndex].ID %>')">
                    <div class="name"><%=ConversationMessages[LastIndex].SenderName%></div>
                    <div class="short-content">
                        <span class="last-short-content" id="ShortContent-<%=ConversationMessages[LastIndex].ID %>">
                            <% 
                                int lIndex = ConversationMessages[LastIndex].Content.IndexOf("<br />", 0);
                                if (lIndex < 0) {
                                    Response.Write(StringUtils.CutStringChar(ConversationMessages[LastIndex].Content, 50));
                                }
                                else {
                                    string shortContent = ConversationMessages[LastIndex].Content.Substring(0, lIndex);
                                    Response.Write(StringUtils.CutStringChar(shortContent, 50));
                                }
                            %>
                        </span>
                        &nbsp;
                    </div>
                    <div class="right">
                    <% if (ConversationMessages[LastIndex].SentUserKey == CurrentUserKey) { %>
                        <input type="button" class="delete-message" onclick="DeleteMessage('<%=ConversationMessages[LastIndex].ID %>', 's')" title="Xóa tin nhắn này" />
                    <% }
                       else { %>
                        <input type="button" class="delete-message" onclick="DeleteMessage('<%=ConversationMessages[LastIndex].ID %>', 'r')" title="Xóa tin nhắn này" />
                    <% } %>
                    </div>
                </div>
                <div class="content display-content" id="MessageContent-<%=ConversationMessages[LastIndex].ID %>"><%=ConversationMessages[LastIndex].Content %></div>
        </div>
    </div>
    <div class="footer">
        <div class="reply-form form">
            <label class="reply-title">Trả lời: </label>
            <textarea id="ReplyContent" class="reply-content input textarea" title="Xin nhập nội dung tin trả lời vào đây"></textarea>
        </div>
        <div class="submit">
            <input type="button" id="btnReplyMessage" name="btn-Reply" />
        </div>
    </div>
    <input type="hidden" id="ConversationID" value="<%=ConversationMessages[0].ConversationID %>" />
    <% }
       else { %>
        <div class="empty-page">Không tồn tại cuộc hội thoại trên hoặc đã bị xóa. Quay về trang <a href="/profile/messages">quản lý tin nhắn</a></div>
    <% } %>
</div>
